package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import org.testng.annotations.Test;
import com.example.utils.ListOf;
import static org.hamcrest.Matchers.*;

public class TestFolderCreation extends TestBase {
	
	@Test
	public void testFolderCreation() throws Exception {
	    // save old state
	    ListOf<FolderData> oldList = app.getFoldersHelper().getFolders();
		
	    // actions
        FolderData folderData = new FolderData().withName("New Folder");
		app.getFoldersHelper().createFolder(folderData);
		
		// save new state
        ListOf<FolderData> newList = app.getFoldersHelper().getFolders();
		
		// compare states
        oldList.add(folderData);
		assertThat(newList, equalTo(oldList));
	}

    @Test
    public void testVariousFolderCreation() throws Exception {
        // save old state
        ListOf<FolderData> oldList = app.getFoldersHelper().getFolders();

        // actions
        FolderData folderData1 = new FolderData().withName("New Folder 1");
        FolderData folderData2 = new FolderData().withName("New Folder 2");
        app.getFoldersHelper().createFolder(folderData1);
        app.getFoldersHelper().createFolder(folderData2);

        // save new state
        ListOf<FolderData> newList = app.getFoldersHelper().getFolders();

        // compare states
        oldList.add(folderData1);
        oldList.add(folderData2);
        assertThat(newList, equalTo(oldList));
    }

    @Test
    public void testDuplicateFolderCreation() throws Exception {
        // save old state
        ListOf<FolderData> oldList = app.getFoldersHelper().getFolders();

        // actions
        FolderData folderData1 = new FolderData().withName("New Folder 3");
        FolderData folderData2 = new FolderData().withName("New Folder 3");
        app.getFoldersHelper().createFolder(folderData1);
        String exceptionString = new String();
        try {
            app.getFoldersHelper().createFolder(folderData2);
        } catch (Exception e) {
            exceptionString = e.toString();
        }
        assertThat(exceptionString, containsString("Duplicated folder name"));

        // save new state
        ListOf<FolderData> newList = app.getFoldersHelper().getFolders();

        // compare states
        oldList.add(folderData1);
        assertThat(newList, equalTo(oldList));
    }


}
